package com.weicx.wuzhiops.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weicx.wuzhiops.annotation.EventLog;
import com.weicx.wuzhiops.annotation.RestWrapper;
import com.weicx.wuzhiops.constant.event.EventType;
import com.weicx.wuzhiops.model.request.EntryPropertyRequest;
import com.weicx.wuzhiops.model.wrapper.DataGrid;
import com.weicx.wuzhiops.service.EntryPropertyService;
import com.weicx.wuzhiops.util.ServletsUtil;
import com.weicx.wuzhiops.util.Valid;
import com.weicx.wuzhiops.vo.EntryPropertyVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author:
 * @date: 2022-12-08 15:28:27
 * @since: 1.0
 */
@Api(value = "资产入库", tags = {"资产入库"})
@RestController
@RestWrapper
@RequestMapping(ServletsUtil.BASE_REQUEST_PATH_PREFIX + "/entry/property")
public class EntryPropertyController {

    @Resource
    private EntryPropertyService entryPropertyService;


    @PostMapping("/add")
    @ApiOperation(value = "新增入库资产")
    @EventLog(value = EventType.ADD_ENTRY_PROPERTY)
    public Long addEntryProperty(@RequestBody EntryPropertyRequest request) {
        Valid.notEmpty(request.getName());
        Valid.notEmpty(request.getClassroom());
        return entryPropertyService.addEntryProperty(request);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除入库资产")
    @EventLog(value = EventType.DELETE_ENTRY_PROPERTY)
    public Integer delete(@RequestBody EntryPropertyRequest request) {
        List<Long> idList = request.getIdList();
        Valid.notEmpty(idList);
        return entryPropertyService.deleteEntryProperty(idList);
    }


    @PostMapping("/update")
    @ApiOperation(value = "修改入库资产")
    @EventLog(value = EventType.UPDATE_ENTRY_PROPERTY)
    public Integer update(@RequestBody EntryPropertyRequest request) {
        Valid.notNull(request.getId());
        return entryPropertyService.updateEntryProperty(request);
    }



    @PostMapping("/list")
    @ApiOperation(value = "获取资产入库列表")
    public DataGrid<EntryPropertyVO> list(@RequestBody EntryPropertyRequest request) {
        return entryPropertyService.listEntryProperty(request);
    }


    @PostMapping("/get")
    @ApiOperation(value = "根据id获取入库资产")
    public EntryPropertyVO getEntryProperty(@RequestBody EntryPropertyRequest request) {
        Long id = Valid.notNull(request.getId());
        return entryPropertyService.getEntryProperty(id);
    }

}
